package com.ts.audioplayer

import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.IBinder
import android.util.Log
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.ts.audioplayer.listener.IPlayerListener
import com.ts.audioplayer.listener.MNOnParparedListener
import java.io.File

class MusicService : Service() {
    /*操作指令*/

    val ACTION_OPT_MUSIC_PLAY: String = "ACTION_OPT_MUSIC_PLAY"

    val ACTION_OPT_MUSIC_PAUSE: String = "ACTION_OPT_MUSIC_PAUSE"

    val ACTION_OPT_MUSIC_RESUME: String = "ACTION_OPT_MUSIC_RESUME"

    val ACTION_OPT_MUSIC_NEXT: String = "ACTION_OPT_MUSIC_NEXT"

    val ACTION_OPT_MUSIC_LAST: String = "ACTION_OPT_MUSIC_LAST"

    val ACTION_OPT_MUSIC_SEEK_TO: String = "ACTION_OPT_MUSIC_SEEK_TO"

    val ACTION_OPT_MUSIC_LEFT: String = "ACTION_OPT_MUSIC_LEFT"

    val ACTION_OPT_MUSIC_RIGHT: String = "ACTION_OPT_MUSIC_RIGHT"

    val ACTION_OPT_MUSIC_CENTER: String = "ACTION_OPT_MUSIC_CENTER"

    val ACTION_OPT_MUSIC_VOLUME: String = "ACTION_OPT_MUSIC_VOLUME"


    private  val TAG = "MusicService"
    override fun onBind(intent: Intent): IBinder?=null;


    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onCreate() {
        super.onCreate()
        initBoardCastReceiver()

    }

    private fun initBoardCastReceiver() {
        val intentFilter = IntentFilter()
        intentFilter.addAction(ACTION_OPT_MUSIC_PLAY)
        intentFilter.addAction(ACTION_OPT_MUSIC_PAUSE)
        intentFilter.addAction(ACTION_OPT_MUSIC_RESUME)
        intentFilter.addAction(ACTION_OPT_MUSIC_NEXT)
        intentFilter.addAction(ACTION_OPT_MUSIC_LAST)
        intentFilter.addAction(ACTION_OPT_MUSIC_SEEK_TO)
        intentFilter.addAction(ACTION_OPT_MUSIC_LEFT)
        intentFilter.addAction(ACTION_OPT_MUSIC_RIGHT)
        intentFilter.addAction(ACTION_OPT_MUSIC_VOLUME)
        intentFilter.addAction(ACTION_OPT_MUSIC_CENTER)
        LocalBroadcastManager.getInstance(this).registerReceiver(mMusicReceiver!!, intentFilter)

    }

    var mMusicReceiver:MusicReceiver?=MusicReceiver()


//    fun play(){
//        tsPlayer?.start()
//    }

    inner class MusicReceiver: BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent?) {
            val action = intent!!.action
            Log.i(TAG, "onReceive: $action")
            if (action ==ACTION_OPT_MUSIC_PLAY) {
//                play()
            }
        }


    }


}